﻿using System;
using Prepare.Domain.Entities;

namespace Prepare.Domain
{
    public static class TestManager
    {
		private static IRepository<Test> Repository
		{
			get { return UnitOfWork.GetRepository<Test>(); }
		}

		private static PrepareEntities Context
		{
			get { return UnitOfWork.GetContext<PrepareEntities>(); }
		}

		public static Test CreateTest()
		{
			Random r = new Random((int)DateTime.Now.Ticks);

			// Create a new Test.
			Test Test = new Test();
			Test.TestKey = GenerateName();
			Test.TotalTime = r.Next(100, 500);

			// Save the Test.
			Repository.Add(Test);

			return Test;
		}

        private static string GenerateName()
        {
            string name = "";

            string[] front = 
            {
                "Fang",
                "Rubon",
                "Slar",
                "Xen",
                "Dread"
            };

            string[] back =
            {
                "icus",
                "ozore",
                "anar",
                "edren"
            };

            Random r = new Random((int)DateTime.Now.Ticks);

            int i = r.Next(front.Length);
            name = front[i];

            i = r.Next(back.Length);
            name += back[i];

            return name;
        }
    }
}
